// 入口文件

const { app } = require("electron");
const {
  create: createMainWindow,
  show: showMainWindow,
  close: closeMainWindow,
} = require("./windows/main");
const handleIPC = require("./ipc");
const gotTheLock = app.requestSingleInstanceLock();

// 禁止软件多开
if (!gotTheLock) {
  app.quit();
} else {
  app.on("second-instance", () => {
    showMainWindow();
  });

  app.on("ready", () => {
    // 创建主窗体
    createMainWindow();

    // 处理进程通讯
    handleIPC();

    require("./trayAndMenu");

    // 加载并执行 robot
    require("./robot.js")();
  });

  app.on("before-quit", () => {
    closeMainWindow();
  });
  app.on("activate", () => {
    showMainWindow();
  });
}
